﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DatingWebSite.DatingService;

using System.Net.Mail;

namespace DatingWebSite.Common
{
    public class Common
    {
        public static int AuthenticateMember(string userName, string Password, int TenentID, string SecureKey)
        {

            int memberProfileID = -1;
            DatingService.DatingService objFetch = new DatingService.DatingService();

            MemberProfile[] members = objFetch.MemberProfileSelectAll(TenentID, SecureKey);


            var iResult = from s in members
                          where s.UserName.Equals(userName) && s.Passwrd.Equals(Password)
                          select new { ProfileID = s.ProfileID };

            foreach (var result in iResult)
            {
                if (result.ProfileID >= 0)
                {
                    memberProfileID = result.ProfileID;
                    break;
                }
            }

            return memberProfileID;
        }



        public static bool SendMail(string sTo, string sFrom, string sSubject, string sBody)
        {
            bool flag = false;

            try
            {
                MailMessage mail = new MailMessage();
                mail.To.Add(sTo);
                mail.From = new MailAddress(sFrom);
                mail.Subject = sSubject;
                mail.Body = Convert.ToString(sBody); ;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = ConfigurationManager.AppSettings["SMTP"];
                smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);
                //smtp.EnableSsl = true;
                smtp.Send(mail);
                flag = true;

            }

            catch (Exception e)
            {
                flag = false;
            }

            return flag;


        }



        public static string InitCap(string sName)
        {
            string returnValue = "";
            if (sName != "")
            {
                returnValue = sName.Substring(0, 1).ToUpper() +
                sName.Substring(1).ToLower();
            }

            return returnValue;
        }



    }


 



}
    
